package com.fz.controller.system;

import com.fz.aop.login.AnonymousAccess;
import com.fz.common.ResponseEntity;
import com.fz.dto.system.menu.MenuAdd;
import com.fz.dto.system.menu.MenuQuery;
import com.fz.dto.system.menu.MenuUpd;
import com.fz.service.system.MenuService;
import com.fz.vo.system.menu.MenuTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@Api(tags = "菜单管理")
@RequestMapping("/menu")
@SuppressWarnings("unchecked")
@ApiSort(value = 4)
public class MenuController{

    @Resource
    private MenuService menuService;

    @GetMapping("/findMenu")
    @ApiOperation(value = "菜单树")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    public ResponseEntity<MenuTreeVo> findMenu(MenuQuery menuQuery) throws Exception{
        return menuService.findMenu(menuQuery);
    }

//    @GetMapping("/findMenuTree")
//    @ApiOperation(value = "全体查询目录树状目录列表，新增，修改，重置的刷新界面获取数据的接口")
//    @ApiOperationSupport(order = 2)
//    @AnonymousAccess
//    public ResponseEntity<MenuTreeVo> findMenuTree() throws Exception{
//        return ResponseEntity.buildSuccess(menuService.findMenuTree());
//    }

    @PostMapping("/addMenu")
    @ApiOperation(value = "新增菜单")
    @ApiOperationSupport(order = 3)
    @AnonymousAccess
    public ResponseEntity addMenu(@RequestBody MenuAdd menuAdd) throws Exception{
        menuService.addMenu(menuAdd);
        return ResponseEntity.buildSuccess();
    }

    @PostMapping("/updateMenu")
    @ApiOperation(value = "修改菜单")
    @ApiOperationSupport(order = 4)
    @AnonymousAccess
    public ResponseEntity updateMenu(@RequestBody MenuUpd menuUpd) throws Exception{
        menuService.updateMenu(menuUpd);
        return ResponseEntity.buildSuccess();
    }

}
